<style>
    #layui-upload-box li,#layui-upload-image-box li{
        width: 120px;
        height: 100px;
        float: left;
        position: relative;
        overflow: hidden;
        margin-right: 10px;
        border:1px solid #ddd;
    }
    #layui-upload-box li img,#layui-upload-image-box li img{
        width: 120px;
        height: 100px;
    }
    #layui-upload-box li p,#layui-upload-image-box li p{
        width: 100%;
        height: 22px;
        font-size: 12px;
        position: absolute;
        left: 0;
        bottom: 0;
        line-height: 22px;
        text-align: center;
        color: #fff;
        background: rgba(0,0,0,.6);
    }
    #layui-upload-box li i,#layui-upload-image-box li i{
        display: block;
        width: 20px;
        height:20px;
        position: absolute;
        text-align: center;
        top: 2px;
        right:2px;
        z-index:999;
        cursor: pointer;
    }

    .close-img{
        position: absolute;
        z-index: 100;
        top: 0;
        right: 5px;
        font-size: 20px;
        color:#fff;
    }

</style>
<script>
    layui.use(['upload'],function () {
        var upload = layui.upload

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#uploadPic'
            ,url: '{{ route("uploadImg") }}'
            ,multiple: false
            ,data:{"_token":"{{ csrf_token() }}"}
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                /*obj.preview(function(index, file, result){
                 $('#layui-upload-box').append('<li><img src="'+result+'" /><p>待上传</p></li>')
                 });*/
                obj.preview(function(index, file, result){
                    $('#layui-upload-box').html('<li><img src="'+result+'" /><p>上传中</p></li>')
                });

            }
            ,done: function(res){
                //如果上传失败
                if(res.code == 0){
                    $("#thumb").val(res.url);
                    $('#layui-upload-box li p').text('上传成功');
                    return layer.msg(res.msg);
                }
                return layer.msg(res.msg);
            }
        });

        //多图片上传
        var count = $("input#imgnum").val()
        var ind = Number(count);
        var uploadImages = upload.render({
            elem: '#uploadImages'
            ,url: '{{ route("uploadImg") }}'
            ,multiple: true
            ,number: 10
            ,data:{"_token":"{{ csrf_token() }}"}
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                /*obj.preview(function(index, file, result){
                 $('#layui-upload-box').append('<li><img src="'+result+'" /><p>待上传</p></li>')
                 });*/
                obj.preview(function(index, file, result){
                    var html = '<li><img src="'+result+'" /><p>上传中</p></li>'
//                    $('#layui-upload-image-box').html('<li><img src="'+result+'" /><p>上传中</p></li>')
                    $('#layui-upload-image-box').append(html)
                });

            }
            ,done: function(res){
                //如果上传成功

                if(res.code == 0){
                    var html = '<input type="hidden" name="images['+ind+'][bigimg]" value="'+ res.url +'" /><input type="hidden" name="images['+ind+'][smallimg]" value="'+ res.small +'" /><span class="layui-icon layui-icon-close-fill close-img" onclick="delImage(this)"></span>'
                    $("#layui-upload-image-box li:last-child").append(html);
                    ind +=1;
                    $('#layui-upload-image-box li p').text('上传成功');

                    return layer.msg(res.msg);
                }
                return layer.msg(res.msg);
            }
        });
    })
    function delImage(obj) {
        $(obj).parent().remove()
    }

</script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container');
    ue.ready(function() {
        ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.
    });
</script>